package enterprise.manage.dao;

import enterprise.manage.entity.Purchases;
import enterprise.manage.entity.Role;
import enterprise.manage.util.StringUtilsExt;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.hibernate.HibernateDao;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: zhenmingyue
 * Date: 2011-7-4 17:59:36
 * Desc:
 * For :
 */
@Repository
@Transactional
public class RoleDao extends HibernateDao<Role, Long> {
    // 角色查询  权限查询            UserDetailsServiceImpl

//    public List<Role> getRolesByUserId(Long id) {
//        Object[] objects = {id};
//        List  list = new ArrayList();
//        List<Role>   resultList = new ArrayList<Role>();
//        String sql = "select r.id,r.createTime,r.roleName,r.roleAlias,r.roleLevel,r.remark,r.deleted from mg.User AS s, mg.user_role as sr,mg.Role as r WHERE s.id = sr.userId and sr.roleId = r.id and s.id =  ?";
//        try{
//            list = this.getJdbcTemplate().queryForList(sql, objects);
//        } catch (Exception e){
//            e.printStackTrace();
//        }
//        for(Object o:list){
//            Role role = new Role();
//            Map map = (Map)o;
//            role.setId((Long) map.get("id"));
//            role.setRoleName(StringUtilsExt.toString(map.get("roleName")));
//            role.setRoleAlias(StringUtilsExt.toString(map.get("roleAlias")));
//            role.setCreateTime((Date)map.get("createTime") );
//            role.setRoleLevel((Integer)map.get("roleLevel"));
//            role.setRemark(StringUtilsExt.toString(map.get("remark")));
//            role.setDeleted((Integer)map.get("deleted"));
//            resultList.add(role);
//        }
//        return resultList;
//    }
}
